import http from '@/utils/http'
import convert from '@/utils/model-convert'
import {FormArgument} from '@/models/customer/questionnaire-survey'

const URL = '/rest/customer/platform/client-surveys'
const OPERATE_URL = '/rest/customer/platform/client-surveys/{id}'

export default {
  addQuestionnaire (form, cb) {
    const data = convert.toJson(form, FormArgument)
    http.put(URL, data, {
      headers: {
        'Content-Type': 'application/json'
      }
    }).then(response => cb(response)).catch(trace => cb(trace.response))
  },
  updateQuestionnaire ({id, form}, cb) {
    const data = convert.toJson(form, FormArgument)
    http.put(OPERATE_URL.replace('{id}', id), data, {
      headers: {
        'Content-Type': 'application/json'
      }
    }).then(response => cb(response)).catch(trace => cb(trace.response))
  },
  delete ({id}, cb) {
    http.delete(OPERATE_URL.replace('{id}', id))
      .then(response => cb(response)).catch(trace => cb(trace.response))
  },
  get ({id}, cb) {
    http.get(OPERATE_URL.replace('{id}', id))
      .then(response => cb(response)).catch(trace => cb(trace.response))
  }
}
